package com.ymk.cmd;

import com.ymk.base.cmd.ACmd;
import com.ymk.base.cmd.CmdSign;
import com.ymk.base.utlis.ParamsBuilder;
import com.ymk.bo.goods.GoodsCartBO;
import com.ymk.core.code.cmd.GoodsCmdCode;
import com.ymk.service.IGoodsCartService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.servlet.http.HttpServletRequest;
import java.util.Map;

@Service
public class GoodsCartDelCmd extends ACmd {

    @Override
    public CmdSign executeStore(HttpServletRequest request, CmdSign sign) throws Exception {
        CmdSign respSign = new CmdSign(sign);
        GoodsCartBO reqData = super.getData(sign, GoodsCartBO.class);

        ParamsBuilder paramsBuilder = ParamsBuilder.newBuild()
                .addParam("id", reqData.getId());
        this.goodsCartService.del(paramsBuilder.build());

        return respSign;
    }

    @Override
    public CmdSign executeServer(HttpServletRequest request, CmdSign sign) throws Exception {
        CmdSign respSign = new CmdSign(sign);
        Map param = super.getData(sign, Map.class);
        this.goodsCartService.del(param);
        return respSign;
    }

    @Override
    public String getCmdCode() {
        return GoodsCmdCode.GOODS_CART_DEL;
    }

    @Autowired
    private IGoodsCartService goodsCartService;
}